#define  _CRT_SECURE_NO_WARNINGS

#include"FileName.h"

int Date::GetMonthDay(int year, int month)
{
	assert((month < 13) && (month > 0));
	int arr[13] = {0, 31,28,31,30,31,30,31,31,30,31,30,31 };
	if (month == 2)
	{
		if (((year % 4 == 0) && (year % 100 != 0)) ||
			year % 400 == 0)
		{
			return 29;
		}
	}
	return arr[month];
}


Date::Date(int year , int month, int day)
{
	_year = year;
	_month = month;
	_day = day;
}

Date::Date(const Date& d2)
{
	/*_year = d2._year;
	_day = d2._day;
	_month = d2._month;*/
	*this = d2;
}

Date& Date::operator=(const Date& d2)
{
	_day = d2._day;
	_month = d2._month;
	_year = d2._year;
	return *this;
}

Date& Date::operator+=(int day)
{
	if (day < 0)
	{
		*this -= day;
	}
	_day += day;
	int ret = GetMonthDay(_year, _month);
	while (_day > ret)
	{
		_day -= ret;
		_month++;
		if (_month > 12)
		{
			_year++;
			_month = 1;
		}
		ret = GetMonthDay(_year, _month);
	}
	return *this;
}

Date Date::operator+(int day)
{
	Date ret(*this);
	ret += day;
	return ret;
}

Date& Date::operator-=(int day)
{
	if (day < 0)
	{
		*this += day;
	}
	_day -= day;
	int ret = GetMonthDay(_year, _month);
	while (_day < 1)
	{
		_day += ret;
		--_month;
		if (_month < 1)
		{
			_year--;
			_month = 12;
		}
		ret = GetMonthDay(_year, _month);
	}
	return *this;
}

Date Date::operator-(int day)
{
	Date ret(*this);
	ret -= day;
	return ret;
}

Date Date::operator++()
{
	++_day;
	if (_day > GetMonthDay(_year, _month))
	{
		_month++;
		if (_month > 12)
		{
			_year++;
			_month = 1;
		}
		_day = 1;
	}
	return *this;
}

Date Date::operator++(int)
{
	Date ret(*this);
	++*this;
	return ret;
}

Date& Date::operator--()
{
	--_day;
	if (_day == 0)
	{
		_month--;
		if (_month == 0)
		{
			_month = 12;
			_year--;
		}
		_day = GetMonthDay(_year, _month);
	}
	return *this;
}

Date Date::operator--(int)
{
	Date ret(*this);
	_day--;
	return ret;
}

bool Date::operator>(const Date& ret)
{
	if (_year > ret._year)
	{
		return true;
	}
	if (_month > ret._month)
	{
		return true;
	}
	if (_day > ret._day)
	{
		return true;
	}

	return false;
}

bool Date::operator==(const Date& ret)
{
	if (_year != ret._year)
	{
		return false;
	}
	if (_month != ret._month)
	{
		return false;
	}
	if (_day != ret._day)
	{
		return false;
	}

	return true;
}

bool Date::operator>=(const Date& ret)
{
	if ((*this > ret) || (*this == ret))
	{
		return true;
	}
	return false;
}

bool Date::operator<(const Date& ret)
{
	if ((*this > ret) || (*this == ret))
	{
		return false;
	}
	return true;
}

bool Date::operator<=(const Date& ret)
{
	if (*this > ret)
	{
		return false;
	}
	return true;
}

bool Date::operator!=(const Date& ret)
{
	if (*this == ret)
	{
		return false;
	}
	return true;
}

int Date::operator-(Date ret)
{
	int i = 1;
	Date d2 = *this;
	int nub = 0;
	if (*this < ret)
	{
		i = -1;
		d2 = ret;
		ret = d2;
	}
	while (d2 != ret)
	{
		++ret;
		nub++;
	}

	return nub * i;
}


